type name = string
type age = int
type adress = string
type telephone = int
type contact = (name * age * adress * telephone)
type agenda = contact list




let rec exist x list =
match list with
  |[] -> false
  |e::l -> if e=x then
      true 
    else 
      exist x l ;;

let rec add_list x list =
match list with
  |[] -> [x]
  |e::l when x<e -> x::e::l
  |e::l when x=e -> x::l
  |e::l when x>e -> e::add_list x l ;;

let rec remove_list x list =
match list with
  |[] -> []
  |e::l when x<e -> invalid_arg "l'element n'existe pas dans la liste"
  |e::l when x=e -> l
  |e::l when x>e -> e::remove_list x l ;;


let rec map f list =
match list with
  |[] -> [] 
  |e::l -> f e::map f l ;;

let rec iter f list =
match list with
  |[] -> []
  |e::l -> f e::iter f l ;;

let rec for_all f list =
match list with
  |[] -> true 
  |e::l -> if f e = true then
      for_all f l
    else 
      false;;

let upper_case lettre =
  let x = int_of_char lettre in
     if x>96 && x<123 then
       char_of_int (x-32)
     else
       lettre;;

let lower_case lettre  =
  let x = int_of_char lettre in
     if x>64 && x<91 then
       char_of_int (x+32)
     else
       lettre;;

let string_of_char c = String.make 1 c;;

let string_apply f character =
  let length = (String.length character) -1 in
  let rec apply i character string =
match i with
  |i when i = length -> string^(string_of_char (f character.[i]))
  |i -> apply (i+1) character (character^(string_of_char (f character.[i]))) in
apply 0 character "";;
				
